package com.example.mymatch.controller;

import com.example.mymatch.model.Role;
import com.example.mymatch.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;  //对某个业务服务的内容进行定义规范  编写者：吴茂景
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制类的实现
 * 编写者：吴茂景
 */
@Api(tags = "角色")
@RestController
public class RoleController {
    @Autowired
    private IRoleService roleService;//对某个业务服务的内容进行定义规范  编写者：吴茂景

    @ApiOperation(value = "查询所有角色信息",notes = "获取角色信息返回json字符串")
    @RequestMapping("/getStr3")
    public String getRole(){
        return "My role";
    }
    @CrossOrigin
    @ApiOperation(value = "对角色信息的添加方法")
    @GetMapping("/addRole")
    public int addRole(Role role){
        System.out.println("进入添加角色信息接口");
        return roleService.insertRole(role);
    }

    @GetMapping("getAll3")
    @ApiOperation(value = "对角色信息的查询方法")
    public List<Role> getAllRole(Role role){
        System.out.println("进入查询方法");

        List<Role> listRole=roleService.getAllRole(role);

        return listRole;
    }

    @PutMapping("/editRole")
    @ApiOperation(value = "对角色信息的修改方法")
    public int EditRole(@RequestBody Role role){
        System.out.println("进入角色修改方法");
        return roleService.updateRole(role);
    }

    @GetMapping("/delRole")
    @ApiOperation(value = "对角色信息的删除方法")
    public int Delete(int id){
        System.out.println("进入角色删除方法");
        int returnValue=0;
        if (id!=0){
            Role role=new Role();
            role.setId(id);
            returnValue= roleService.deleteRole(role);
        }
        return returnValue;
    }

    @GetMapping("/getOne3")
    @ApiOperation(value = "对单条角色信息的查询方法")
    public  Role getRole(int id){
        Role role=new Role();
        System.out.println("进入角色查询方法");
        if (id!=0){
            Role role1=new Role();
            role1.setId(id);
            role=roleService.getRole(role1);
            System.out.println("返回的数据集合为："+role.getRoleName());
        }
        return role;
    }
}
